package com.hlhj.funlike_businessqzxd.moudle;

import android.content.Context;

import com.example.mymvp.mvp.BaseModule;
import com.hlhj.funlike_businessqzxd.api.Apis;
import com.hlhj.funlike_businessqzxd.api.BaseObser;
import com.hlhj.funlike_businessqzxd.bean.FoodListBean;
import com.hlhj.funlike_businessqzxd.bean.MsgBean;
import com.lzy.okgo.model.Response;

import java.util.List;

public class FoodFragmentMoudle implements BaseModule {
    public interface getFoodList{
        void loadFoodList(List<FoodListBean.DataBeanX.DataBean> dataBeans);

        void loadFoodStatus(String msg);
    }

    public getFoodList listener;

    public void setListener(getFoodList listener) {
        this.listener = listener;
    }

    public void LoadFoodList(Context context,int type_id,int p,int num){
        Apis.INSTANCE.FoodList(type_id,p,num)
                .subscribe(new BaseObser<Response<FoodListBean>>(context) {
                    @Override
                    public void httpSuccess(Response<FoodListBean> foodListBeanResponse) {
                        if (listener!=null){
                            listener.loadFoodList(foodListBeanResponse.body().getData().getData());
                        }
                    }
                });
    }

    public void LoadFoodStatus(Context context,int id,int status){
        Apis.INSTANCE.FoodStatus(id,status)
                .subscribe(new BaseObser<Response<MsgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<MsgBean> msgBeanResponse) {
                        if (listener!=null){
                            listener.loadFoodStatus(msgBeanResponse.body().getMsg());
                        }
                    }
                });
    }
}
